{{Extend "layout"}}
{{Block "title"}}{{$.Stored.title}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li><a href="{{BackendURL}}/cloud/backup">{{"云备份配置列表"|$.T}}</a></li>
<li class="active">{{$.Stored.title}}</li>
{{/Block}}
{{Block "main"}}
<div class="row">
  <div class="col-md-12">
    <div class="block-flat no-padding">
      <div class="header">
        <h3>{{$.Stored.title}}</h3>
      </div>
      <div class="content">
        <form class="form-horizontal group-border-dashed" id="account-add-form" method="POST" action="">
          <div class="form-group">
            <label class="col-sm-2 control-label">{{"名称"|$.T}}</label>
            <div class="col-sm-3">
              <input type="text" class="form-control" name="name" placeholder="{{`名称`|$.T}}" value="{{$.Form `name`}}" required>
              <div class="help-block">{{`配置名称`|$.T}}</div>
            </div>
            <label class="col-sm-2 control-label">{{"延时操作"|$.T}}</label>
            <div class="col-sm-3">
              <span class="input-group">
                <input type="number" class="form-control" name="delay" value="{{$.Form `delay`}}" placeholder="{{`秒`|$.T}}" step="1" min="0">
                <span class="input-group-addon">{{`秒`|$.T}}</span>
              </span>
              <div class="help-block">{{`延时操作。0表示不延时`|$.T}}</div>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">{{"源路径"|$.T}}</label>
            <div class="col-sm-8">
              <input type="text" class="form-control" name="sourcePath" value="{{$.Form `sourcePath`}}" placeholder="" required="required">
              <div class="help-block">
                {{- if $.Stored.fileSources -}}{{`除了指定本机存储设备上的文件外，还支持添加如下前缀来指定特殊位置的文件：`|$.T}}<br />
                {{- range $k,$v:=$.Stored.fileSources -}}
                {{- if gt $k 0 -}}<br />{{- end -}}
                <code>{{$v.Name}}</code> {{$v.Description}}
                {{- end -}}
                {{- end -}}
              </div>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">{{"忽略路径"|$.T}}</label>
            <div class="col-sm-8">
              <input type="text" class="form-control" name="ignoreRule" value="{{$.Form `ignoreRule`}}" placeholder="/\.git/|/.svn/">
              <div class="help-block">{{`正则表达式`|$.T}}</div>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">{{"匹配规则"|$.T}}</label>
            <div class="col-sm-8">
              <input type="text" class="form-control" name="matchRule" value="{{$.Form `matchRule`}}" placeholder="(\.tar\.gz|\.zip)$">
              <div class="help-block">
                {{`正则表达式`|$.T}}<br />
                {{`如果设置了“匹配规则”，则“忽略规则”自动失效`|$.T}}
              </div>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">{{"等待填充"|$.T}}</label>
            <div class="col-sm-8">{{$waitFillCompleted := $.Form "waitFillCompleted" "N"}}
              <div class="radio radio-primary radio-inline">
                <input type="radio" value="Y" id="waitFillCompleted-Y" name="waitFillCompleted"{{if eq $waitFillCompleted `Y`}} checked{{end}}><label for="waitFillCompleted-Y">{{"启用"|$.T}}</label>
              </div>
              <div class="radio radio-danger radio-inline">
                <input type="radio" value="N" id="waitFillCompleted-N" name="waitFillCompleted"{{if eq $waitFillCompleted `N`}} checked{{end}}><label for="waitFillCompleted-N">{{"禁用"|$.T}}</label>
              </div>
              <div class="help-block">{{`等待文件填充完成。当监测到文件被修改时，可能文件尚未写入完毕，此时除了可以通过设置前面的“延时操作”来解决外，也可以启用此功能。但是注意要排除掉永远不会结束写入的文件，比如session文件等`|$.T}}</div>
              <div class="fieldset bg-fc" id="ignoreWaitRuleBox"{{if eq $waitFillCompleted `N`}} style="display:none;"{{end}}>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"忽略等待"|$.T}}</label>
                <div class="col-sm-8">
                  <input type="text" class="form-control" name="ignoreWaitRule" value="{{$.Form `ignoreWaitRule`}}" placeholder="">
                  <div class="help-block">{{`正则表达式，例如：session\.bson。留空代表不限制`|$.T}}</div>
                </div>
              </div>
              </div>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">{{"最小修改间隔"|$.T}}</label>
            <div class="col-sm-3">
              <span class="input-group">
                <input type="number" class="form-control" name="minModifyInterval" value="{{$.Form `minModifyInterval` `5`}}" placeholder="{{`秒`|$.T}}" step="1" min="0">
                <span class="input-group-addon">{{`秒`|$.T}}</span>
              </span>
            </div>
            <div class="col-sm-5"><div class="help-block">{{`设置最小修改间隔可以避免短时间内重复上传`|$.T}}</div></div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label required">{{"目的地"|$.T}}</label>
            <div class="col-sm-8">{{$engine := $.Form `storageEngine`}}
              <select name="storageEngine" id="storageEngine" class="form-control xs-margin-bottom">
                {{- range $k, $v := $.Stored.engines -}}
                <option value="{{$v.K}}"{{if eq $engine $v.K}} selected{{end}}>{{$v.V}}</option>
                {{- end -}}
              </select>
              <div class="fieldset bg-fc">
                <div class="form-group dest-path">
                  <label class="col-sm-2 control-label required">{{"目标路径"|$.T}}</label>
                  <div class="col-sm-8">
                    <input type="text" class="form-control" name="destPath" value="{{$.Form `destPath`}}" placeholder="">
                    <div class="help-block"></div>
                  </div>
                </div>
              </div><!-- .fieldset -->
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{"日志"|$.T}}</label>
            <div class="col-sm-3">{{$v := $.Form "logDisabled"}}
              <div class="radio radio-primary radio-inline">
                  <input type="radio" value="N" name="logDisabled"{{if eq $v `N` ``}} checked{{end}} id="logDisabled-N"> <label for="logDisabled-N">{{"开启"|$.T}}</label>
                </div>
              <div class="radio radio-primary radio-inline">
                  <input type="radio" value="Y" name="logDisabled"{{if eq $v `Y`}} checked{{end}} id="logDisabled-Y"> <label for="logDisabled-Y">{{"关闭"|$.T}}</label>
                </div>
            </div>
            <label class="col-sm-2 control-label">{{"记录内容"|$.T}}</label>
            <div class="col-sm-3">{{$v := $.Form "logType" "error"}}
              <div class="radio radio-primary radio-inline">
                  <input type="radio" value="error" name="logType"{{if eq $v `error` ``}} checked{{end}} id="logType-error"> <label for="logType-error">{{"仅记录报错信息"|$.T}}</label>
                </div>
              <div class="radio radio-primary radio-inline">
                  <input type="radio" value="all" name="logType"{{if eq $v `all`}} checked{{end}} id="logType-all"> <label for="logType-all">{{"全部记录"|$.T}}</label>
                </div>
            </div>
          </div>

          <div class="form-group">
            <label class="col-sm-2 control-label">{{"状态"|$.T}}</label>
            <div class="col-sm-8">{{$v := $.Form "disabled"}}
              <div class="radio radio-primary radio-inline">
                <input type="radio" value="N" id="disabled-N" name="disabled"{{if eq $v `N` ``}} checked{{end}}><label for="disabled-N">{{"启用"|$.T}}</label>
              </div>
              <div class="radio radio-danger radio-inline">
                <input type="radio" value="Y" id="disabled-Y" name="disabled"{{if eq $v `Y`}} checked{{end}}><label for="disabled-Y">{{"禁用"|$.T}}</label>
              </div>
            </div>
          </div>
          <div class="form-group form-submit-group">
            <div class="col-sm-8 col-sm-offset-2">
              <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> {{"保存"|$.T}}</button>
              <button type="reset" class="btn btn-default btn-lg"><i class="fa fa-refresh"></i> {{"重置"|$.T}}</button>
            </div>
          </div>
        </form>
      </div><!-- /.content -->
    </div><!-- /.block-flat -->
  </div>
</div>
{{/Block}}
{{Block "footer"}}
<script src="{{AssetsURL}}/js/loader/loader.min.js?t={{BuildTime}}"></script>
<script src="{{AssetsURL}}/js/editor/editor.min.js?t={{BuildTime}}"></script>
{{- range $k, $forms := $.Stored.engineForms -}}
<script type="text/html" id="config-tmpl-{{$k}}">
{{- range $i, $f := $forms -}}
<div class="form-group">
  {{- $v := $.Form $f.Name -}}
  <label class="col-sm-2 control-label{{if $f.Required}} required{{end}}">{{$f.Label|$.T}}</label>
  <div class="col-sm-8">
  <input type="{{$f.Type}}" id="config-{{$f.Name}}" class="form-control" name="{{$f.Name}}" data-init="{{$v}}" value="{{$v}}"{{if $f.Required}} required{{end}}{{if $f.Pattern}} pattern="{{$f.Pattern}}"{{end}}{{if $f.Placeholder}} placeholder="{{$f.Placeholder}}"{{end}}>
  </div>
</div>
{{- end -}}
</script>
{{- end -}}
<script type="text/javascript">
$(function(){
  $('#storageEngine').on('change',function(){
    var eng=$(this).val();
    var box=$(this).next('.fieldset').children('.dest-path');
    box.siblings('div.form-group').remove();
    switch(eng){
      case 's3': box.before($('#config-tmpl-'+eng).html()); 
        App.editor.selectPage('#config-destStorage',{data:BACKEND_URL+'/cloud/storage'});break
      case 'sftp': box.before($('#config-tmpl-'+eng).html()); 
        App.editor.selectPage('#config-destStorage',{data:BACKEND_URL+'/term/account',eAjaxMethod:'GET'});break
      case 'ftp': box.before($('#config-tmpl-'+eng).html());break
      case 'webdav': box.before($('#config-tmpl-'+eng).html());break
      case 'smb': box.before($('#config-tmpl-'+eng).html());break
      default: break
    }
  }).trigger('change');
  $('input[name="waitFillCompleted"]').on('click',function(){
    var v=$(this).val();
    if(v=='Y'){
      $('#ignoreWaitRuleBox').show();
    }else{
      $('#ignoreWaitRuleBox').hide();
    }
  });
  $('input[name="waitFillCompleted"]:checked').trigger('click');
});
</script>
{{/Block}}